// arttemplate helper方法定义
define([
  "artlib"
], function(template){
	var methods = {};

	// ============================================ 不需要调用的helper

	/**
	 * @Author    高同檩
	 * @DateTime  2017-12-18
	 * @copyright [字段展示 有值渲染值没值渲染指定的值]
	 * @param     {[key]}    字段值     传入的字段值
	 * @param     {[sym]}    字段值     字段为空的值
	 * @return    {[string]}            处理好的字符串
	 */
	template.defaults.imports.resoleValue = function(key,sym){
    var sSym = sym ? sym : "--";
    return key ? key : sSym;
  }

  /**
	 * @Author    高同檩
	 * @DateTime  2017-12-18
	 * @copyright [列表级联样式展示 三级 1-2-3 二级 1-2 一级 1 无 --]
	 * @param     {[key]}    需要级联的数组(每一项级联的值)
	 * @return    {[string]}            处理好的字符串
	 */
	template.defaults.imports.resoleCascadeValue = function(key){
    var aArry = key;
    var iIdx = null;
    var sStr = "";
    for(var i = 0; i < aArry.length; i++){
    	if(!aArry[i]){
    		iIdx = i;
    		break;
    	}else{
    		iIdx = aArry.length;
    	}
    }
    if(iIdx == 0){
    	sStr = "--";
    }else{
    	sStr += aArry[0];
    	for(var j = 1; j < iIdx; j++){
    		sStr += ("-" + aArry[j]);
    	}
    }

    return sStr;
  }

  // ============================================ 需要调用的helper

	/**
	 * @Author    高同檩
	 * @DateTime  2017-12-18
	 * @copyright [arttemplate-helper 将数字转换成字母]
	 * @param     {[key]}    number     数字索引
	 * @return    {[string]}            处理好的
	 */
	methods.parseNumberToLetter = function(key){
	  template.defaults.imports.parseNumberToLetter = function(key){
	    var obj = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"];
	    return obj[key];
	  }
	}

	/**
	 * @Author    高同檩
	 * @DateTime  2018-1-22
	 * @copyright [arttemplate-helper 解析支付方式信息]
	 * @param     {[key]}    string     文字标识
	 * @return    {[string]}            文字标识对应的名称
	 */
	methods.artHelpParsePayInfor = function(key){
	  template.defaults.imports.artHelpParsePayInfor = function(key){
	    var oConfig = {
	    	account: "账户余额",
	    	cash: "现金",
	    	weixin: "微信支付",
	    	alipay: "支付宝",
	    	qrpos: "扫码POS",
	    	pos: "刷卡POS",
	    	banktransfer: "银行转账",
	    	cheque: "支票"
	    }
	    return oConfig[key];
	  }
	}

	/**
	 * @Author    高同檩
	 * @DateTime  2018-1-23
	 * @copyright [arttemplate-helper 截取数组展示 eg 1,2,3...]
	 * @param     {[arrayData]}    array     数据 eg: [{cost:100, id:1, name:123}]
	 * @param     {[cutNum]}    number     需要截断的数据个数
	 * @param     {[key]}     	string    对象对应的key
	 * @return    {[string]}            处理后的值
	 */
	methods.artHelpListArrayShow = function(arrayData, cutNum, key){
	  template.defaults.imports.artHelpListArrayShow = function(arrayData, cutNum, key){
	    if(!arrayData || !arrayData.length){
	    	return "--";
	    }
	    var sStr = "";
	    for(var i = 0; i < arrayData.length; i++){
	    	if(i == cutNum){
	    		sStr += "...";
	    		break;
	    	}
	    	var sArrayStr = "";
	    	if( typeof arrayData[i] == "object" ){
	    		sArrayStr = arrayData[i][key]
	    	}else{
	    		sArrayStr = arrayData[i]
	    	}
	    	sStr += (sArrayStr + ",");
	    }
	    return sStr.replace(/\,$/ig, "");
	  }
	}

	/**
	 * @Author    高同檩
	 * @DateTime  2018-1-23
	 * @copyright [arttemplate-helper 截取数组展示 eg 1,2,3...]
	 * @param     {[arrayData]}    array     数据 eg: [{cost:100, id:1, name:123}]
	 * @param     {[columnNum]}    number     一行几个数据
	 * @param     {[key]}     	string    对象对应的key
	 * @return    {[string]}            处理后的值
	 */
	methods.artHelpListArrayTip = function(arrayData, columnNum, key){
	  template.defaults.imports.artHelpListArrayTip = function(arrayData, columnNum, key){
	    if(!arrayData || !arrayData.length){
	    	return "";
	    }
	    var sStr = "";
	    for(var i = 0; i < arrayData.length; i++){
	    	var sArrayStr = "";
	    	if( typeof arrayData[i] == "object" ){
	    		sArrayStr = arrayData[i][key]
	    	}else{
	    		sArrayStr = arrayData[i]
	    	}
	    	sStr += (sArrayStr + ",");
	    	if( (i-1)%columnNum == 0 && i > 0){
	    		sStr += "\n";
	    	}
	    }
	    return sStr.replace(/,$/ig, "\n").replace(/\n$/ig, "");
	  }
	}

	

	return methods;
})